# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgbase=fcitx5-pinyin-zhwiki
pkgname=(fcitx5-pinyin-zhwiki rime-pinyin-zhwiki)
_converterver=0.2.4
_zhwikiver=20231001
_webslangver=20231016
pkgver=$_converterver.$_webslangver
pkgrel=1
epoch=1
pkgdesc="Fcitx 5 Pinyin Dictionary from zh.wikipedia.org"
arch=('any')
url="https://github.com/felixonmars/fcitx5-pinyin-zhwiki"
license=('CCPL:by-sa' 'custom:GFDL')
makedepends=('libime' 'opencc' 'pypinyin')
source=(https://github.com/felixonmars/fcitx5-pinyin-zhwiki/archive/$_converterver/$pkgbase-$_converterver.tar.gz
        https://github.com/felixonmars/fcitx5-pinyin-zhwiki/releases/download/$_converterver/web-slang-$_webslangver.source
        https://dumps.wikimedia.org/zhwiki/$_zhwikiver/zhwiki-$_zhwikiver-all-titles-in-ns0.gz
        https://www.gnu.org/licenses/fdl-1.3.txt)
sha512sums=('f03215f0c6e137238a8c9f0ba557bf933ca2d4faf8c2a3aaa84f5e58485c8e0ace57f24d0cd855aa7a1d7e3001b4b36427c9a47ad04b92d11847bb5dbd24a709'
            'b919df2e3f58f14d3fbde832985ff8970d0b28101c52c9191b992a825e2d23dfcf5d953d21fc06ecf9d26f4f6449271f561bf52b868744e21ce730dce7ea300b'
            'f381986b9cdbe45e14ae48f76904478fa91453e9b31bb5c5c4c8e4a8282bc44747e70aedeecb188ac8b8a2a47f72e7b41237dd36383fb051a71707d89c69bc90'
            '22d46818d3998ad841f537af4de7c50440dd918099fb6c5d4ab324cd71dc03066bfe1b67210a5efde77abd1d97b88da3c3dbfc39a24ae7248ee2d64e7f0fe6bb')

_make="make -L VERSION=$_zhwikiver WEB_SLANG_VERSION=$_webslangver"

prepare() {
  cd $pkgbase-$_converterver
  # Workaround pacman decompression
  touch zhwiki-$_zhwikiver-all-titles-in-ns0.gz
  ln -s ../zhwiki-$_zhwikiver-all-titles-in-ns0
  ln -s ../web-slang-$_webslangver.source
}

build() {
  cd $pkgbase-$_converterver
  $_make zhwiki.dict zhwiki.dict.yaml
}

package_fcitx5-pinyin-zhwiki() {
  cd $pkgbase-$_converterver
  $_make DESTDIR="$pkgdir" install
  install -Dm644 ../fdl-1.3.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}

package_rime-pinyin-zhwiki() {
  cd $pkgbase-$_converterver
  $_make DESTDIR="$pkgdir" install_rime_dict
  install -Dm644 ../fdl-1.3.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
